package combobox;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;

import database.Database;

public class ComboboxModel extends DefaultComboBoxModel{
    /**
	 * 
	 */
	private static final long serialVersionUID = -2018661075891274966L;
	
	public static ImageIcon ICON_DATABASE;

    public ComboboxModel() {
        loadIcon();        
    }
    
    protected final void loadIcon(){
        ICON_DATABASE = new ImageIcon(getClass().getResource("/res/database-icon-16.png"));
    }
    
    public void addDatabase(String db){    	
    	addElement(new ListboxItem(ICON_DATABASE, 0, db));
    }
    
    public void removeDatabase(int index){    	
    	removeElementAt(index); 	
    }
    
    public void removeDatabase(String name){    	
    	int i = 0;
    	while (i < getSize()){
    		ListboxItem item = (ListboxItem)getElementAt(i);
    		String db = item.m_data;
    		if (db.equals(name))
    		{
    			removeElementAt(i);    			
    			return;
    		}
    		i++;
    	}    	    	
    }    
}
